home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / COMMS / C011.ZIP / LTYPE.C < prev    next >
Text File  |  1990-01-19  |  4KB  |  179 lines

  1. /********************************************************************
  2.  * C Users Group (U.K) C Source Code Library File CUGLIB.011        *
  3.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  4.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  5.  ********************************************************************
  6.  * File name: ltype.c
  7.  * Program name: ltype
  8.  * Source of file: The Public Domain Software Library.
  9.  * Purpose: types a member of a library.
  10.  * Changes: <who what when & why major changes have been made>      
  11.  ********************************************************************/
  12.  
  13. /* LTYPE -  */
  14.  
  15. #define    VERSION        3
  16. #define REVISION    0
  17. #define MOD_DATE    "84-03-01"
  18.  
  19. /* This program will type a member of a LBR file... any member,
  20.    BUT anything other than an ASCII file will produce a screenful
  21.    of garbage.
  22.  
  23.    USE: LTYPE <library> <member>
  24.    COMPILE/LINK: cc1 ltype
  25.          nl2 ltype libacc
  26.    By S. Kluger 01-13-83
  27.  
  28.    vers 3.0   3-1-84
  29.    Upgrade to lattice c ms dos P. H. Mack.
  30. */
  31.  
  32. #include "stdio.h"
  33.  
  34. char curdsk, fcb[36];
  35. char fnam[12], libnam[16], dirbuf[128], *dirp;
  36. int  fd, dirsiz, filsiz;
  37.  
  38. #define OK    0
  39.  
  40. /************************************************
  41.  main
  42. *************************************************/
  43.  
  44. main(argc,argv)
  45. int argc;
  46. char **argv;
  47. {
  48.     cprintf("\n\rLTYPE vers:%d.%02d  %s\n\r\n",
  49.     VERSION,REVISION,MOD_DATE);
  50.  
  51.     opnlib(argv[1]);
  52.     if (fndmem(argv[2]) == ERROR) erxit("\n\rMember not in LBR file!\n\r");
  53.     cprintf("\n\rFile present - %d sectors.\n\r",filsiz);
  54.     doit();
  55. }
  56.  
  57. /************************************************
  58.  Typing function 
  59. *************************************************/
  60.  
  61. doit()
  62.  
  63. {
  64.     int    j;
  65.     int    c;
  66.  
  67.     dirsiz = filsiz;
  68.     do
  69.     {
  70.         reload();
  71.  
  72.         for (j=0; j<128; j++){
  73.  
  74.             if (*dirp == 0x1a)
  75.                 exit();
  76.             putchar(*dirp);
  77.             if(*dirp == 0x0a)
  78.             putchar('0x0d');
  79.             dirp++;
  80.         }
  81.     }while(dirsiz != 0);
  82. }
  83.  
  84. /************************************************
  85.  open library file
  86. *************************************************/
  87.  
  88.  
  89. opnlib(file)
  90. char *file;
  91. {
  92.     char l, *npnt;
  93.  
  94.     strcpy(libnam,file);
  95.     l = matchr(libnam,'.');
  96.     if (l == 0) strcat(libnam, ".LBR");
  97.     setfcb(fcb,libnam);    /* build name in fcb */
  98.     movmem(fcb,fnam,12);    /* get from dfcb2 for log */
  99.  
  100.     if(strcmp(fcb+9, "LBR")){
  101.         printf("got %s\n",libnam);
  102.         erxit("Invalid file spec, MUST be type .LBR\n");
  103.     }
  104.  
  105.     fd = open(libnam,0x8000);
  106.     if(fd == -1) erxit("Library file not found.\n");
  107. }
  108.  
  109. /************************************************
  110.  find library member
  111. *************************************************/
  112.  
  113. fndmem(file)
  114. char *file;
  115. {
  116.     char dnam[16], fname[36];
  117.     long int    floc;
  118.  
  119.     setfcb(fname, file);
  120.     read(fd,dirbuf,128);
  121.     dirp = dirbuf;
  122.     dirsiz = *(dirp+14);
  123.     dirp += 32;
  124.  
  125.     do{
  126.         if (*dirp == 255) return(ERROR);
  127.         if (*dirp == 0){
  128.             strcpy(dnam, dirp+1);
  129.             dnam[11]=0;
  130.             if(strcmp(dnam, fname+1) == 0){
  131.                 filsiz = (*(dirp+14)) + ((*(dirp+15)) * 256);
  132.                 floc=(*(dirp+12)) + ((*(dirp+13)) * 256);
  133.                 lseek(fd,floc *128,0);
  134.                 return(OK);
  135.             }
  136.         }
  137.         dirp += 32;
  138.         if(dirp > dirbuf+128) reload();
  139.     }
  140.     while(dirsiz);
  141.     return(ERROR);
  142. }
  143.  
  144. /************************************************
  145.  reload
  146. *************************************************/
  147.  
  148. reload()
  149. {
  150.     read(fd,dirbuf,128);
  151.     dirp = dirbuf;
  152.     dirsiz--;
  153. }
  154.  
  155. /************************************************
  156.  match char
  157. *************************************************/
  158.  
  159. char matchr(st,ch)
  160. char *st,ch;
  161. {
  162.     int i;
  163.     for(i=0; st[i]; i++){
  164.         if(st[i] == ch) return(i);
  165.     }
  166.     return(0);
  167. }
  168.  
  169. /************************************************
  170.  error exit
  171. *************************************************/
  172.  
  173. erxit(strg)
  174. char *strg;
  175. {
  176.     printf(strg);
  177.     exit();
  178. }
  179.